package com.sgb.kjwl.view.ui.adapter.packers;

import android.content.Context;
import android.text.TextUtils;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.self.SelfTeamMemberEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

/**
 * @date 2021/3/15
 * @author F_Q
 * Description:选择工队人员条目处理
 */
public class WorkPersonnelAdapter  extends BaseRecycleAdapter<SelfTeamMemberEntity> {

    public WorkPersonnelAdapter(Context context, List<SelfTeamMemberEntity> data) {
        super(context, R.layout.item_work_personnel, data);
    }

    @Override
    public void convert(ItemViewHolder holder, final SelfTeamMemberEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        //头像
        ImageView workerAvatar = holder.itemView.findViewById(R.id.user_logo);
        RequestOptions options = new RequestOptions();
        options.transforms(new CenterCrop(), new RoundedCorners(8));
        if (TextUtils.isEmpty(entity.getAvatarAddress())) {
            Glide.with(context).load(R.mipmap.worker_avatar).into(workerAvatar);
        } else {
            Glide.with(context).load(entity.getAvatarAddress()).apply(options).into(workerAvatar);
        }
        //年龄和工龄
        TextView tvWorkerInfo = holder.itemView.findViewById(R.id.workerInfo);
        tvWorkerInfo.setText(entity.getWorkingYear() + "年工龄");

        TextView tvPhone = holder.itemView.findViewById(R.id.tv_phones);
        tvPhone.setText(entity.getContactPhone());
        CheckBox checkBox = holder.itemView.findViewById(R.id.checkbox);
        checkBox.setChecked(entity.isLooks());
        LinearLayout details = holder.itemView.findViewById(R.id.details);
        checkBox.setOnClickListener(v -> {
            boolean isLooked = entity.isLooks();
            entity.setLooks(!isLooked);
            checkedBox.selectData();
            notifyDataSetChanged();
        });
        details.setOnClickListener(v -> checkedBox.detailsData(entity.getNo()));
    }
    private OnCheckedChangeCheckBox checkedBox;

    public void setCheckedBox(OnCheckedChangeCheckBox checkedBox) {
        this.checkedBox = checkedBox;
    }

    public interface OnCheckedChangeCheckBox {

        void selectData();

        void detailsData(String no);
    }
}
